package yaq.mini.weibo.leafwb.mapper;

import yaq.mini.weibo.leafwb.pojo.Article;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ArticleMapper {

    Article getFullArticleByID(String articleId);

    List<Article> listFullArticle();

    List<Article> listFullArticleOrderByTimeLimit(int count);

    List<Article> listFullArticleOrderByTime();

    List<Article> listFullArticleByUserId(String userId);

    List<Article> listFullArticleByContent(String content);

    @Select("select * from article where articleId = #{articleId} order by releaseTime desc")
    Article getArticleByID(String articleId);

    @Select("select * from article where articleId = #{articleId order by releaseTime desc")
    List<Article> getListArticleByID(String articleId);

    @Insert("insert into article values(#{articleId},#{userId},#{content},#{releaseTime},#{likeNum},#{commentCount},#{authority})")
    int insert(Article article);

    @Update("update article set likeNum = likeNum + #{likeNum} where articleId=#{articleId}")
    int updateByLikeNum(String articleId, Long likeNum);

    @Update("update article set commentCount = commentCount + #{commentCount} where articleId=#{articleId}")
    int updateByCommentCount(String articleId, int commentCount);

    @Update("update article set authority=#{authority} where articleId=#{articleId}")
    int updateByAuthority(String articleId,int authority);

    @Delete("delete from article where articleId=#{articleId}")
    int deleteArticleByID(String articleId);

}
